﻿using System;
using System.IO;
using System.Windows.Forms;

namespace CDude.Vita
{
    internal class GlobalTools
    {
        private const string ERROR_OUT_FILE_PATH = "error_log_gui.txt";

        //Save exception data to a file
        public static bool SaveException(Exception ex)
        {
            try
            {
                string sout = ex.Message + "\r\n" + ex.StackTrace;
                using (StreamWriter sw = new StreamWriter(ERROR_OUT_FILE_PATH))
                    sw.Write(sout);

                return true;
            }
            catch (Exception exx)
            {
                MessageBox.Show("Could not save stack trace to file!\n\n" + exx.Message + "\n" + exx.StackTrace, "Exception caught – VitaCOMgui", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
    }
}